package com.zhaosc.shiro.web.controller;

import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhaosc.shiro.bind.annotation.CurrentUser;
import com.zhaosc.shiro.model.Resource;
import com.zhaosc.shiro.model.User;
import com.zhaosc.shiro.service.ResourceService;
import com.zhaosc.shiro.service.UserService;

/**
 * 
 * @Description:TODO
 * @author:zhaosc
 * @time:2017年8月18日
 * @exception
 */
@Controller
public class IndexController {

	@Autowired
	private ResourceService resourceService;
	@Autowired
	private UserService userService;
	
    @RequestMapping("/")
	public String index(@CurrentUser User loginUser, Model model){
		Set<String> permissions=userService.findPermissions(loginUser.getUsername());
		List<Resource> menus=resourceService.findMenus(permissions);
		model.addAttribute("menus", menus);
		return "index";
	}
	
	  @RequestMapping("/welcome")
	    public String welcome() {
	        return "welcome";
	   }
}
